package com.scuec.trainingmanagementsys.service.impl;

import com.scuec.trainingmanagementsys.entity.DailyReport;
import com.scuec.trainingmanagementsys.mapper.DailyReportMapper;
import com.scuec.trainingmanagementsys.service.DailyReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class DailyReportServiceImpl implements DailyReportService {

    @Autowired
    private DailyReportMapper dailyReportMapper;

    @Override
    public List<DailyReport> findAll() {
        return dailyReportMapper.findAll();
    }

    @Override
    public boolean deleteById(Integer dailyReportID) {
        if (dailyReportID == null || dailyReportID <= 0) {
            return false;
        }
        int affectedRows = dailyReportMapper.deleteById(dailyReportID);
        return affectedRows > 0;
    }

    @Override
    public boolean insert(DailyReport dailyReport) {
        // 自动设置创建时间
        dailyReport.setDrCreateTime(new Date());

        int affectedRows = dailyReportMapper.insert(dailyReport);
        return affectedRows > 0;
    }

    @Override
    public List<DailyReport> findByStudentID(Integer studentID) {
        return dailyReportMapper.findByStudentID(studentID);
    }

//    @Override
//    public List<DailyReport> findByProjectID(Integer projectID) {
//        return dailyReportMapper.findByProjectID(projectID);
//    }

    @Override
    public List<Map<String, Object>> findAllWithRelations() {
        return dailyReportMapper.findAllWithRelations();
    }

    @Override
    public List<Map<String, Object>> findByStudentIDWithRelations(Integer studentID) {
        return dailyReportMapper.findByStudentIDWithRelations(studentID);
    }

    @Override
    public List<Map<String, Object>> findByProjectIDWithRelations(Integer projectID) {
        return dailyReportMapper.findByProjectIDWithRelations(projectID);
    }

    @Override
    public List<Map<String, Object>> getDailyCountLast7Days() {
        return dailyReportMapper.selectDailyCountLast7Days();
    }
}